package com.wutuo.roster.provider.component;

import cn.apestar.base.SpringContextHolder;
import cn.apestar.chat.provider.component.UserDataTranslate;
import cn.apestar.core.utils.TranslateUtil;
import cn.apestar.util.CommonUtil;
import com.wutuo.institution.provider.service.InstitutionWTService;
import com.wutuo.roster.api.response.ChildApplyResponse;
import com.wutuo.roster.api.response.ParentsResponse;
import com.wutuo.roster.provider.enums.EnumList;
import com.wutuo.wtservice.provider.service.ServiceService;

import java.util.ArrayList;
import java.util.List;

public class ChildApplyDataConvert {

    private static ServiceService serviceService =
        SpringContextHolder.getBean(ServiceService.class);

    private static InstitutionWTService institutionService = SpringContextHolder.getBean("institutionWTService");


    // 翻译
    public static void convertToCustomerResponseList(List<ChildApplyResponse> list) {

        TranslateUtil
            .translatEnumList(list, "userType", "userTypeName", EnumList.getUserEnumList());
        serviceService.getUseServiceByIds(list, "tgType", "tgTypeList");
        institutionService.getCminstanById(list, "cmInstitutionId", "institutionResponse", false);
        UserDataTranslate.convertToUserResponseList(list, "userId", "parentsingle");
        for (int i = 0; i < list.size(); i++) {
            ChildApplyResponse childApplyResponse = list.get(i);
            if (childApplyResponse.getParentsingle() != null) {
                List<ParentsResponse> parents = new ArrayList();
                ParentsResponse parent = new ParentsResponse();
                parent
                    .setUserType(CommonUtil.toLong(childApplyResponse.getUserType(), new Long(0)));
                parent.setUserName(childApplyResponse.getParentsingle().getUserName());
                parent.setUserPhone(childApplyResponse.getParentsingle().getAccount());
                parent.setUserId(childApplyResponse.getUserId());
                parent.setUserTypeName(childApplyResponse.getUserTypeName());
                childApplyResponse.getParent().add(parent);
            }
        }
    }

}
